package main

import (
	"fmt"
	"os"
)

func main() {
	path := "./02_file_write.txt"
	writeFile(path)
}

func writeFile(path string) {
	file, err := os.Create(path)
	if err != nil {
		fmt.Println(" file-err : ", err)
		return
	}

	defer file.Close()

	var buffer string

	for i := 0; i < 20; i++ {
		buffer = fmt.Sprintf(" j = %d \n ", i)
		fmt.Println(" \t buffer = ", buffer)
		fn, ferr := file.WriteString(buffer)
		if ferr != nil {
			fmt.Println(" write-err : ", ferr)
		}
		fmt.Println(" fn = ", fn)
	}

}
